﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using BLL.DataContextClasses;

namespace BLL.BusinessClasses
{
    public class Pais
    {
         //Campos
        private int id;
        private string descripcion;

        //Propiedades
        public int ID
        {
            get { return this.id; }
        }
        public string Descripcion
        {
            get { return this.descripcion; }
            set { this.descripcion = value; }
        }

        //Constructores
        public Pais(int IDToSearch)
        {
            try
            {
                DataClassesDataContext DB = new DataClassesDataContext();

                DataContextClasses.Paise Pai = (from c in DB.Paises
                                                  where c.ID == IDToSearch
                                                  select c).First();

                this.id = Pai.ID;
                this.descripcion = Pai.Descripcion;
            }
            catch (SqlException SqlEx)
            {
                throw new Exception("No existe tal pais\n" + SqlEx.Message);
            }
        }

        //Metodos
        public static Pais GetPaisByEmpresaID(int EmpresaID)
        {
            try
            {
                DataClassesDataContext DB = new DataClassesDataContext();

                DataContextClasses.Empresa Emp = (from e in DB.Empresas
                                                    where e.ID == EmpresaID
                                                    select e).First();

                return new Pais(Emp.ID_Pais);
            }
            catch (SqlException SqlEx)
            {
                throw new Exception("Hubo un problema con la base de datos\n" + SqlEx.Message);
            }
        }

        public static Pais GetPaisByVacanteID(int VacanteID)
        {
            try
            {
                DataClassesDataContext DB = new DataClassesDataContext();

                DataContextClasses.Vacante Vac = (from v in DB.Vacantes
                                                  where v.ID == VacanteID
                                                  select v).First();

                return new Pais(Vac.ID_Pais);
            }
            catch (SqlException SqlEx)
            {
                throw new Exception("Hubo un problema con la base de datos\n" + SqlEx.Message);
            }
        }
    }
}
